<!DOCTYPE html>
<!-- saved from url=(0080)http://www.zhangyunling.com/study/slideUpDownRefresh/version_1/iscroll-test.html -->
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta charset="utf-8">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
    <title>slideUpDownRefresh</title>
    <link rel="stylesheet" type="text/css" href="slideUpDownRefresh_files/bootstrap.css">
    <link rel="stylesheet" type="text/css" href="slideUpDownRefresh_files/bootstrap-theme.css">
    <link rel="stylesheet" type="text/css" href="slideUpDownRefresh_files/iscroll.css">
</head>
<body onload="page.init()">
<div id="wrapper">
    <div id="scroller">
        <div id="scroller-pullDown">
            <span id="down-icon" class="icon-double-angle-down pull-down-icon"></span>
            <span id="pullDown-msg" class="pull-down-msg">下拉刷新</span>
        </div>
        <div id="scroller-content">
            <ul>
                <li>Pretty row 1</li>
                <li>Pretty row 2</li>
                <li>Pretty row 3</li>
                <li>Pretty row 4</li>
                <li>Pretty row 5</li>
                <li>Pretty row 6</li>
                <li>Pretty row 7</li>
                <li>Pretty row 8</li>
                <li>Pretty row 9</li>
                <li>Pretty row 10</li>
                <li>Pretty row 11</li>
                <li>Pretty row 12</li>
                <li>Pretty row 13</li>
                <li>Pretty row 14</li>
                <li>Pretty row 15</li>
                <li>Pretty row 16</li>
                <li>Pretty row 17</li>
                <li>Pretty row 18</li>
                <li>Pretty row 19</li>
                <li>Pretty row 20</li>
                <li>Pretty row 21</li>
                <li>Pretty row 22</li>
                <li>Pretty row 23</li>
                <li>Pretty row 24</li>
                <li>Pretty row 25</li>
                <li>Pretty row 26</li>
                <li>Pretty row 27</li>
                <li>Pretty row 28</li>
                <li>Pretty row 29</li>
                <li>Pretty row 30</li>
                <li>Pretty row 31</li>
                <li>Pretty row 32</li>
                <li>Pretty row 33</li>
                <li>Pretty row 34</li>
                <li>Pretty row 35</li>
                <li>Pretty row 36</li>
                <li>Pretty row 37</li>
                <li>Pretty row 38</li>
                <li>Pretty row 39</li>
                <li>Pretty row 40</li>
                <li>Pretty row 41</li>
                <li>Pretty row 42</li>
                <li>Pretty row 43</li>
                <li>Pretty row 44</li>
                <li>Pretty row 45</li>
                <li>Pretty row 46</li>
                <li>Pretty row 47</li>
                <li>Pretty row 48</li>
                <li>Pretty row 49</li>
                <li>Pretty row 50</li>
            </ul>
        </div>
        <div id="scroller-pullUp">
            <span id="up-icon" class="icon-double-angle-up pull-up-icon"></span>
            <span id="pullUp-msg" class="pull-up-msg">上拉刷新</span>
        </div>
    </div>
</div>

<script type="text/javascript" src="slideUpDownRefresh_files/jquery.min.js"></script>
<script type="text/javascript" src="slideUpDownRefresh_files/iscroll.js"></script>
<script type="text/javascript">


    var page = (function () {

        var myScroll,
                upIcon = $("#up-icon"),
                downIcon = $("#down-icon");

        function loaded() {
            myScroll = new IScroll('#wrapper', {probeType: 3, mouseWheel: true});

            myScroll.on("scroll", function () {
                var y = this.y,
                        maxY = this.maxScrollY - y,
                        downHasClass = downIcon.hasClass("reverse_icon"),
                        upHasClass = upIcon.hasClass("reverse_icon");

                if (y >= 40) {
                    !downHasClass && downIcon.addClass("reverse_icon");
                    return "";
                } else if (y < 40 && y > 0) {
                    downHasClass && downIcon.removeClass("reverse_icon");
                    return "";
                }

                if (maxY >= 40) {
                    !upHasClass && upIcon.addClass("reverse_icon");
                    return "";
                } else if (maxY < 40 && maxY >= 0) {
                    upHasClass && upIcon.removeClass("reverse_icon");
                    return "";
                }
            });

            myScroll.on("slideDown", function () {
                if (this.y > 40) {

                    $("#scroller-pullDown").css("top", "0px");
                    $("#scroller-pullDown #pullDown-msg").html("正在刷新...");
                    page.pullDownAction();
                    upIcon.removeClass("reverse_icon");

                }
            });

            myScroll.on("slideUp", function () {
                console.log("maxScrollY=" + this.maxScrollY + ";this.y=" + this.y);
                if (this.maxScrollY - this.y > 40) {

                    $("#scroller-pullUp").css("bottom", "0px");
                    $("#scroller-pullUp #pullDown-msg").html("正在刷新...");
                    page.pullUpAction();
                    upIcon.removeClass("reverse_icon")
                }
            });
        }


        return {

            init: function () {
                loaded();
            },
            pullDownAction: function () {

                setTimeout(function () {
                    var ul = $("<ul>");
                    for (var i = 0; i < 40; i++) {
                        var li = $("<li>");
                        $(li).html(i + 'pullDown');
                        $(ul).append(li);
                    }
                    $("#scroller-content").html(ul);
                    page.endRefresh();

                }, "2000");
            },
            pullUpAction: function () {

                setTimeout(function () {


                    for (var i = 0; i < 10; i++) {
                        var li = $("<li>");
                        $(li).html(i + 'pullUp');
                        $("#scroller-content ul").append(li);
                    }

                    page.endRefresh();

                }, "2000");

            },
            endRefresh: function () {

                $("#scroller-pullDown").animate({top: "-40px"});
                $("#scroller-pullDown #pullDown-msg").html("下拉刷新");


                $("#scroller-pullUp").animate({bottom: "-40px"});
                $("#scroller-pullUp #pullDown-msg").html("上拉刷新");


                setTimeout(function () {
                    myScroll.refresh();
                }, 0);

            }

        };


    })();


</script>
</body>
</html>